package com.kws.merchant.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kws.merchant.domain.UserAuthEntity;
import com.kws.merchant.domain.vo.AccountManagementVo;
import com.kws.system.api.domain.SysUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author : zhangbenting
 * @date : 2024/11/20 16:57
 * @Version: 1.0
 */
public interface UserAuthMapper extends BaseMapper<UserAuthEntity> {

    @Select("SELECT " +
            " a.user_name AS account, " +
            " a.phonenumber AS phone, " +
            " a.avatar AS head_img, " +
            " a.sex , " +
            " a.nick_name AS user_name, " +
            " b.auth_type  " +
            "FROM " +
            " sys_user AS a " +
            " LEFT JOIN tb_user_auth AS b ON a.user_id = b.user_id  " +
            "WHERE " +
            " a.user_id = 1")
    AccountManagementVo accountManagement(@Param("userId") Long userId);

    @Select("UPDATE sys_user  " +
            "SET nick_name = '${nickName}'  " +
            " WHERE " +
            " user_id = ${userId}")
    boolean updateUserInfo(@Param("nickName") String nickName,
                           @Param("userId") Long userId);

    @Update("UPDATE sys_user " +
            "SET phonenumber = #{phone}, sex = #{sex}, avatar = #{img} " +
            "WHERE user_id = #{userId}")
    boolean updateUser(
            @Param("phone") String phone,
            @Param("sex") String sex,
            @Param("img") String img,
            @Param("userId") Long userId);

    @Select("select * from sys_user where  user_id = ${userId}")
    SysUser getUserById(@Param("userId") Long userId);
}
